package com.funcourse.demo.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Choice {

  @ApiModelProperty("选项编号")
  Integer choiceNumber;

  @ApiModelProperty("废弃字段")
  String choiceDesc;

  @ApiModelProperty("choiceType为TEXT是填文本")
  String choiceContent;

  @ApiModelProperty("choiceType为PIC时填")
  Image image;

  @ApiModelProperty("PIC/TEXT")
  ChoiceType choiceType;

  @ApiModelProperty("正误")
  Boolean right;

  public enum ChoiceType{
    PIC,TEXT;
  }

  public String getChoiceContent(){
    if(StringUtils.isEmpty(this.choiceContent)){
      return this.choiceDesc;
    }
    return this.choiceContent;
  }

  public ChoiceType getChoiceType(){
    return null== this.choiceType ? ChoiceType.TEXT:this.choiceType;
  }

  //兼容choiceContent 和 choiceDesc
  public Image getImage(){
    if(getChoiceType() == ChoiceType.TEXT){
      return null;
    }
    if(null == image){
      this.image = new Image(getChoiceContent(),getChoiceContent());
    }
    return image;
  }

}
